Totally blind stab at implementing speed stuff on Windows, breaking my lovely OS...
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 12 May 2014 15:22:53 +0000 (15:22 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Mon, 12 May 2014 15:22:53 +0000 (15:22 +0000)
want this code over...

gpsbabel/gbser_posix.h [new file with mode: 0644]
gpsbabel/gbser_win.cc
gpsbabel/gbser_win.h [new file with mode: 0644]
gpsbabel/jeeps/gpsserial.cc

diff --git a/gpsbabel/gbser_posix.h b/gpsbabel/gbser_posix.h
new file mode 100644 (file)
index 0000000..d6c5e78
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef gbser_posix_h
+#define gbser_posix_h
+
+#include <termios.h>
+
+speed_t mkspeed(unsigned br);
+
+#endif
index d5a28cd32708ec8c3c3757665a9600b5b3a503d9..4ea910f901a518d4a23f2df3d069f7c50fa7ce1c 100644 (file)
@@ -48,7 +48,7 @@ static gbser_handle* gbser__get_handle(void* p)
   return h;
 }
 
-static DWORD mkspeed(unsigned br)
+DWORD mkspeed(unsigned br)
 {
   switch (br) {
   case   1200:
diff --git a/gpsbabel/gbser_win.h b/gpsbabel/gbser_win.h
new file mode 100644 (file)
index 0000000..7de3c2e
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef gbser_win_h
+#define gbser_win_h
+
+DWORD  mkspeed(unsigned br);
+
+#endif
index 7591a1187f45c189d1eff0cab40ec0b70250def1..0300779820e4bed8daf731c7e0254e6725353f7b 100644 (file)
@@ -60,6 +60,7 @@ char* rxdata[] = {
 #if defined (__WIN32__) || defined (__CYGWIN__)
 
 #include <windows.h>
+#include "gbser_win.h"
 
 typedef struct {
   HANDLE comport;
@@ -226,6 +227,86 @@ int32 GPS_Serial_Read(gpsdevh* dh, void* ibuf, int size)
   return cnt;
 }
 
+// Based on information by Kolesár András from
+// http://www.manualslib.com/manual/413938/Garmin-Gps-18x.html?page=32
+int32 GPS_Serial_Set_Baud_Rate(gpsdevh* fd, int br)
+{
+  static UC data[4];
+  GPS_PPacket tra;
+  GPS_PPacket rec;
+  win_serial_data* wsd = (win_serial_data*)fd;
+  
+  DWORD speed = mkspeed(br);
+
+  // Turn off all requests by transmitting packet
+  GPS_Util_Put_Short(data, 0);
+  GPS_Make_Packet(&tra, 0x1c, data, 2);
+  if (!GPS_Write_Packet(fd,tra)) {
+    return gps_errno;
+  }
+  if (!GPS_Get_Ack(fd, &tra, &rec)) {
+    return gps_errno;
+  }
+  
+  GPS_Util_Put_Int(data, br);
+  GPS_Make_Packet(&tra, 0x30, data, 4);
+  if (!GPS_Write_Packet(fd,tra)) {
+    return gps_errno;
+  }
+  if (!GPS_Get_Ack(fd, &tra, &rec)) {
+    return gps_errno;
+  }
+
+  // Receive IOP_BAUD_ACPT_DATA
+  if (!GPS_Packet_Read(fd, &rec)) {
+    return gps_errno;
+  }
+
+  // Acnowledge new speed
+  if (!GPS_Send_Ack(fd, &tra, &rec)) {
+    return gps_errno;
+  }
+  GPS_Device_Flush(fd);
+  GPS_Device_Wait(fd);
+  
+  // Sleep for a small amount of time, about 100 milliseconds,
+  // to make sure the packet was successfully transmitted to the GPS unit.
+  gb_sleep(100000); 
+  
+  // Change port speed
+  DCB tio;
+  tio.DCBlength = sizeof(DCB);
+
+  GetCommState(wsd->comport, &tio);
+  tio.BaudRate = speed;;
+  if (!SetCommState(wsd->comport, &tio)) {
+    GPS_Serial_Error("SetCommState on port for alternate bit rate failed");
+    CloseHandle(wsd->comport);
+    return 0;
+  }
+
+  GPS_Util_Put_Short(data, 0x3a);
+  GPS_Make_Packet(&tra, 0x0a, data, 2);
+  if (!GPS_Write_Packet(fd,tra)) {
+    return gps_errno;
+  }
+  if (!GPS_Get_Ack(fd, &tra, &rec)) {
+    return gps_errno;
+  }
+
+  GPS_Util_Put_Short(data, 0x3a);
+  GPS_Make_Packet(&tra, 0x0a, data, 2);
+  if (!GPS_Write_Packet(fd,tra)) {
+    return gps_errno;
+  }
+  if (!GPS_Get_Ack(fd, &tra, &rec)) {
+    return gps_errno;
+  }
+  
+  if (global_opts.debug_level >= 1) fprintf(stderr, "Serial port speed set to %d\n", br);
+  return 0;
+  
+}
 #else
 
 #include "gbser_posix.h"
@@ -541,9 +622,8 @@ int32 GPS_Serial_Set_Baud_Rate(gpsdevh* fd, int br)
   static UC data[4];
   GPS_PPacket tra;
   GPS_PPacket rec;
-  speed_t speed;
   
-  speed = mkspeed(br);
+  speed_t speed = mkspeed(br);
 
   // Turn off all requests by transmitting packet
   GPS_Util_Put_Short(data, 0);